package com.example.demo.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.example.demo.domain.dto.ResultDTO;
import com.example.demo.domain.po.Floor;
import com.example.demo.domain.vo.FloorVO;
import com.example.demo.services.FloorServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/floor")
public class FloorController {

    @Autowired
    FloorServices floorServices;

    @GetMapping("getAll")
    public ResultDTO getAll() {
        ResultDTO resultDTO = new ResultDTO();
        List<FloorVO> floorVOS = floorServices.getAll();
        resultDTO.setData(floorVOS);
        resultDTO.setMessage("查询成功");
        return resultDTO;
    }

    @GetMapping("get")
    public ResultDTO get(int id) {
        ResultDTO resultDTO = new ResultDTO();
        FloorVO floorVO = floorServices.get(id);
        resultDTO.setData(floorVO);
        resultDTO.setMessage("查询成功");
        return resultDTO;
    }

    @PostMapping("add")
    public ResultDTO add(Floor floor) {
        floorServices.add(floor);
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setMessage("添加成功");
        return resultDTO;
    }

    @PostMapping("edit")
    public ResultDTO edit(Floor floor) {
        floorServices.edit(floor);
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setMessage("修改成功");
        return resultDTO;
    }

    @GetMapping("del")
    public ResultDTO del(int id) {
        floorServices.del(id);
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setMessage("删除成功");
        return resultDTO;
    }
}
